<template>
	<view class="index-page with-tabbar">
		<view class="page-content">
			<!-- 个人信息 -->
			<view class=" bg-fff p-30 mt-20">
				<div class="flex align-center lh-50 bor-b pb-20">

					<div class="fontS28 ">头像</div>
					<div class=" ml-auto flex align-center">
						<button class="avator flex-center mr-20" open-type="chooseAvatar"
							@chooseavatar="getChooseAvatar">
							<image class="img-60" v-if="userInfo.avatar"
								:src="userInfo.avatar.indexOf('https://') > -1 ? userInfo.avatar : baseUrl + userInfo.avatar"
								mode="aspectFill" />
							<image class="img-60" v-else
								:src="userInfo.sex === '0' ? 'https://apitest.yijiangongxiang.com/template/nan.png' : 'https://apitest.yijiangongxiang.com/template/nv.png'"
								mode="aspectFill" />

						</button>
						<div class="iconfont icon-youjiantou color-6D ml-auto"></div>

					</div>
				</div>
				<div class="flex align-center lh-50 pt-20 pb-20 bor-b"
					@click="update('/pages/setting/modifyInfo', '修改昵称')">
					<div class="fontS28 ">昵称</div>
					<div class=" ml-auto flex align-center">
						<div class="mr-20">{{ userInfo.nickName || '' }}</div>
						<div class="iconfont icon-youjiantou color-6D ml-auto"></div>
					</div>

				</div>
				<div class="flex align-center lh-50 pt-20 pb-20 bor-b">
					<div class="fontS28 ">用户姓名</div>
					<div class="ml-auto color-6D">{{ userInfo.realName || '' }}</div>

				</div>
				<div class="flex align-center lh-50 pt-20 pb-20 bor-b">
					<div class="fontS28 ">用户ID</div>
					<div class="ml-auto color-6D">ID:{{ userInfo.userId }}</div>

				</div>
				<div class="flex align-center lh-50 pt-20 pb-20 bor-b"
					@click="update('/pages/setting/modifyInfo', '微信号')">
					<div class="fontS28 ">微信号</div>
					<div class=" ml-auto flex align-center">
						<div class="mr-20">{{ userInfo.wx || '' }}</div>
						<div class="iconfont icon-youjiantou color-6D ml-auto"></div>
					</div>

				</div>
				<div class="flex align-center lh-50 pt-20">
					<div class="fontS28 ">我的邀请码</div>
					<div class="ml-auto color-6D">{{ userInfo.invitationCode || '' }} <span class="color-green pl-20"
							@click="copyBtn">复制</span>
					</div>
				</div>

			</view>
			<view class=" bg-fff p-30 mt-20" v-if="userInfo.userType === '03'">


				<div class="flex align-center lh-50 pt-20  " :class="userInfo.companyId ? 'bor-b pb-20' : ''">
					<div class="fontS28 ">企业名称</div>
					<div class="auth" v-if="userInfo.companyId">已认证</div>
					<div class="ml-auto color-6D" v-if="userInfo.companyId">{{ userInfo.companyName || '' }}</div>
					<div class="ml-auto color-6D flex-center" v-else @click="toAuth">
						<div>未认证</div>
						<div class="ml-20 iconfont icon-youjiantou"></div>
					</div>


				</div>
				<div v-if="userInfo.companyId">
					<div class="flex align-center lh-50 pt-20 pb-20 bor-b">
						<div class="fontS28 ">企业联系人</div>
						<div class="ml-auto color-6D">{{ userInfo.linker || '' }}</div>

					</div>
					<div class="flex align-center lh-50 pt-20 pb-20 bor-b">
						<div class="fontS28 ">企业联系电话</div>
						<div class=" ml-auto flex align-center">
							<div class="mr-20">{{ userInfo.linkPhone || '' }}</div>
						</div>

					</div>
					<div class="flex align-center lh-50 pt-20">
						<div class="fontS28 ">企业联系地址</div>
						<div class="ml-auto color-6D">{{ userInfo.companyAddress || '' }}
						</div>
					</div>
				</div>
			</view>
		</view>
	</view>
</template>

<script>
const ossUploadFile = require("@/utils/ossupload/upload").ossUploadFile;
import {
	userInfoChange,

} from "@/api/user.js";
export default {

	data() {
		return {
			baseUrl: getApp().globalData.baseUrl,
			postForm: null,
			tempFilePath: "",
		};
	},
	computed: {
		userInfo() {

			return this.$store.getters.userInfo || {};
		},


	},
	async onLoad() {
		this.postForm = this.userInfo
	},
	async onShow() {

	},
	mounted() {

	},
	methods: {
		getChooseAvatar(e) {
			console.log(e)

			this.uploadImages(e.detail.avatarUrl)

		},
		async uploadImages(path, type) {
			let data = { type: 11 };
			data.filePath = path
			ossUploadFile.ossUploadFile(data, async (res) => {

				const { msg } = await userInfoChange({
					headimg: res.fileName
				})
				uni.showToast({ title: msg, icon: 'none' })

			}, async (error) => {
				console.log(error)

			})
		},
		toAuth() {
			uni.navigateTo({
				url: '/pages/auth/companyAuth'
			})
		},
		copyBtn() {
			uni.setClipboardData({
				data: this.userInfo.invitationCode,
				success: function () {
					uni.showToast({
						title: '复制成功',
						icon: 'none'
					});
				},

			});
		},
		update(url, title) {
			uni.navigateTo({
				url: `${url}?title=${title}`
			})
		},

	},
};
</script>

<style lang="less" scoped>
@import url(user.less);

.auth {
	margin-left: 10upx;
	padding: 0upx 20upx;
	height: 46upx;
	border-radius: 100upx;
	line-height: 42upx;
	background: rgba(255, 113, 0, .12);
	color: #FF7100;
	border: 2upx solid #FF7100;


}
</style>
